﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using DTO;
namespace BUS
{
    public class MemberBUS
    {
        public static bool insertMember(MEMBER _mMember)
        {
            try
            {
                if (MemberDAO.IsExisting(_mMember.ACCOUNT.USERNAME.Trim()))
                    return false;
                _mMember.ACCOUNT.ACCOUNT_STYLE = true;
                _mMember.MEMBER_STYLE = 3;
                _mMember.ACCOUNT.VISIBLE = true;
                return MemberDAO.insertMember(_mMember);
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }

        public static bool updateMember(MEMBER _mMember)
        {
            try
            {
                bool isExist = MemberDAO.IsExisting(_mMember.IDMEMBER);
                if (!isExist)
                    return false;
                return MemberDAO.updateMember(_mMember);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int GetIDMax()
        {
            return MemberDAO.GetIDMax();
        }


        public static MEMBER getMember(int idAccount)
        {
            try
            {
                return MemberDAO.getMember(idAccount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static MEMBER getMember(string user_login, string user_password)
        {
            try
            {
                if (!MemberDAO.IsExisting(user_login, user_password))
                    return null;
                return MemberDAO.GetMember(user_login, user_password);
            }
            catch (Exception ex)
            {
                throw ex;
            }
           
        }

        public static bool DeleteMember(int IDMember)
        {
            try
            {
                bool isExist = MemberDAO.IsExisting(IDMember);
                if (!isExist)
                    return false;
                return MemberDAO.DeleteMember(IDMember);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static MEMBER GetMember(int idMember)
        {
            try
            {
                bool isExist = MemberDAO.IsExisting(idMember);
                if (!isExist)
                    return null;
                MEMBER Member = MemberDAO.GetMember(idMember);
                return Member;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
